<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 预解析案例
        /* var num = 10;
        fun();
        function fun() {
            console.log(num);
            var num = 20;
        } */



        // 相当于以下代码:
        /* var = num;
        function fun() {
            var num;
            console.log(num);
            num = 20;
        }
        num = 10;
        fun(); */


        /* var num = 10;
        function fn() {
            console.log(num);
            var num = 20;
            console.log(num);
        }
        fn(); */

        // 相当于以下代码:
        /* var num;
        function fun() {
            var num;
            console.log(num);
            num = 20;
            console.log(num);
        }
        num = 10;
        fn(); */


        /* var a = 18;
        f1();
        function f1() {
            var b = 9;
            console.log(a);
            console.log(b);
            var a = '123';
        } */

        // 相当于以下代码:
        /* var a;
        function f1() {
            var b;
            var a;
            b = 9;
            console.log(a);
            console.log(b);
            a = '123';
        }
        a = 18;
        f1(); */



        f1();
        console.log(c);
        console.log(b);
        console.log(a);
        function f1() {
            var a = b = c = 9;
            console.log(a);
            console.log(b);
            console.log(c);
        }
        // 相当于以下代码:
        /* function f1() {
            var a;
            a = b = c = 9;
            console.log(a);
            console.log(b);
            console.log(c);
        }
        f1();
        console.log(c);
        console.log(b);
        console.log(a); */

        // 这里需要注意的是后面的b和c其实是直接赋值了,所以是全局变量
    </script>
</head>

<body>

</body>

</html>